package com.sakiko.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

// 请求头中内容的接收
@Controller
@ResponseBody
@RequestMapping("header")
public class RequestHeaderController {

    // 需求 1: get /header/show 接收: user-agent
    @GetMapping("show") // @RequestHeader name忽略大小写，但是不会将 - 转成 camel
    public String show(@RequestHeader(name = "user-agent") String userAgent){
        System.out.println("RequestHeaderController.show");
        System.out.println("user-agent: " + userAgent);
        return userAgent;
    }

    // 需求 2: get /header/show?name=root  接收: user-agent、root
    @GetMapping("show2") // 同 param传参接收，这里可以省略 @RequestParam
    public String show2(@RequestHeader(name = "user-agent") String userAgent,String name){
        System.out.println("RequestHeaderController.show");
        System.out.println("user-agent: " + userAgent);
        return userAgent;
    }
}
